package com.lpz.jdbc;

import java.sql.*;

/**
 * 程序的耦合
 */
public class jdbcdemo01 {
    public static void main(String[] args) throws SQLException {
        //1注册驱动
        DriverManager.registerDriver(new com.mysql.jdbc.Driver());
        //2获取连接
        Connection connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/spring","root","123456");
        //3获取操作数据库的预处理对象
        PreparedStatement preparedStatement=connection.prepareStatement("select  * from account");
        //4执行sql，得到结果集
        ResultSet resultSet=preparedStatement.executeQuery();
        //5遍历结果集
        while (resultSet.next()){
            System.out.println(resultSet.getString("name"));
        }
        //6释放资源
        resultSet.close();
        preparedStatement.close();
        connection.close();
    }
}
